package com.application.race.manage.player.skill;
 	
import com.application.actor.pojo.Actor;
import com.application.item.manage.ActorBagManage;
import com.application.race.manage.DEF;
import com.application.race.manage.RacingRoom;
import com.application.race.manage.misc.RacingItem;
import com.application.race.manage.player.Player;
import com.application.race.manage.player.effect.skill.FocusEffect;
import com.application.race.manage.player.effect.skill.HideEffect;
import com.application.race.manage.player.effect.skill.JumpEffect;
import com.application.race.manage.player.effect.skill.RepairEffect;
import com.application.race.manage.player.effect.skill.StrickEffect;

public class SkillChecker
{
    public static int SKILL_TYPE_STRICK=11000;
    public static int SKILL_TYPE_JUMP=11010;
    public static int SKILL_TYPE_REPAIR=11030;
    public static int SKILL_TYPE_REPAIR_CONTINUE=3;
    public static int SKILL_TYPE_FIXING=4;      
    public static int SKILL_TYPE_SENSITIVE=5; 
    public static int SKILL_TYPE_HIDE=11020; 
    public static int SKILL_TYPE_FOCUS=11040; 
    public static int SKILL_TYPE_BOMB=11050; 
    RacingRoom room;
    	
    public SkillChecker(RacingRoom room){
    	this.room=room;
    }
    public void convertSkillToEffect(){
    	
    }
    double abs_x,abs_y;
    boolean onFix=false;
    public void praseStrickSkill(Actor a,int ang,short x,short y,int actionId){
    	Player p=room.getPlayer(a.getId());
    	//if(!p.stock.ubag.removeOneItem(SKILL_TYPE_STRICK))return ;
    	p.addRaceItem(SKILL_TYPE_STRICK);
    	if(actionId<p.actionId){
    		return ;
    	}
		StrickEffect eft=new StrickEffect();
		eft.initiator=a.getId();
		eft.receiver=a.getId();

		eft.x=x;
		eft.y=y;
		eft.ang=ang;
		eft.actionid=castStrickSkill( a,x,y,ang);
		room.actions.addEffect(eft);
    }
    public void praseSkill(Actor a,int skillType){
    	Player p=room.getPlayer(a.getId());
    	if(!ActorBagManage.raceUseItem(a, skillType))return;
        p.addRaceItem(skillType);
    	if(skillType==SKILL_TYPE_JUMP){
    		JumpEffect eft=new JumpEffect();
    		eft.initiator=a.getId();
    		eft.receiver=a.getId();
    		room.actions.addEffect(eft);
    		room.getPlayer(a.getId()).effects.add(eft);
    		room.getPlayer(a.getId()).onJump=true;
    		//castStrickSkill( name);
    		return;
    	}
    	if(skillType==SKILL_TYPE_HIDE){
    		HideEffect eft=new HideEffect();
    		eft.initiator=a.getId();
    		eft.receiver=a.getId();
    		room.actions.addEffect(eft);
    		return;
    	}
    	if(skillType==SKILL_TYPE_REPAIR){
    		RepairEffect eft=new RepairEffect();
    		eft.initiator=a.getId();
    		eft.receiver=a.getId();
            castRepairSkill( eft ,a);
    		room.actions.addEffect(eft);
    		return;
    		
    	}
    	if(skillType==SKILL_TYPE_FOCUS){
    		FocusEffect eft=new FocusEffect();
    		eft.initiator=a.getId();
    		eft.receiver=a.getId();
    		room.actions.addEffect(eft);
    		return;
    	}
    	if(skillType==SKILL_TYPE_BOMB){
    		
    		RacingItem ri=new RacingItem(room,SKILL_TYPE_BOMB);
    		ri.owner=p;
    		ri.x=p._x;
    		ri.y=p._y;
    		ri.maxTime=15000;
    		room.items.add(ri);
    		room.actions.addItem(ri);
    		return;
    	}
    }    
    public int castStrickSkill(Actor a,short x,short y,int ang){
    	
    	Player p=room.getPlayer(a.getId());
    	
    	if(p==null)return p.actionId;
    	//p.actionId++;
        p.clearSideclip();
        p.down_speed=0;
        p.up_speed=p.carInfo.maxUpSpeed;
        p.resetRunParam();

        p._x=x;
        p._y=y;
        p._angle=ang;
		if(p._up){
			if(p._relaseAccelerator){
				p.resetAction();
				p._up=true;
			    p._relaseAccelerator=true;
			}else{
				p.resetAction();
			    p._up=true;	
			}
		
		}else{
			p.resetAction();
			p._up=true;
			p._relaseAccelerator=true;
		}
        p.actionCode=p.action.getCurentActionCode();      
        return p.actionId;
        
        //actorContrl.resetAction();
    }
    public void castRepairSkill(RepairEffect eft,Actor a){
    	Player p=room.getPlayer(a.getId());
    	int bld=0;
    	int absbld=0;
        if(!p.dead){
        	bld=(int)(DEF.random(20, 40)/100.0*p.max_blood);
        	p.now_blood+=bld;
        	
        	if(p.now_blood>p.max_blood){
        		absbld=p.now_blood-p.max_blood;
        		bld=bld-absbld;
        		p.now_blood=p.max_blood;
        		
        	}
            p.heal+=bld;
        }
        eft.nowBlood=p.now_blood;
        eft.addBlood=bld;
        //actorContrl.resetAction();
    } 
 
}
